<template>
  <div style="height:100%">
    <router-view></router-view>
  </div>
</template>

<script>
import axios from "axios";

export default {
  beforeRouteEnter(to, from, next) {
    let currentPath = to.path;
    if (
      currentPath == "/registerTips" ||
      currentPath == "/register" ||
      currentPath == "/home/salecard" ||
      currentPath == "/payment" ||
      currentPath == "/login"
    ) {
      return next();
    }
    let userInfo = localStorage.getItem("userInfo");
    axios.post("http://192.168.1.237:9090/index.php/api/user/checklogin").then(result => {
      /**
       * 判断是否登录
       * 1. true: 判断是否认证
       *    1. true: 跳到认证页
       *    2. false: 跳到本页
       * 2. false: 跳到登录页
       */
      if (result.data.data.islogin == 1) {
        if (userInfo.iscertification == 1) {
          next("/certification");
        } else {
          if (result.data.activation == 0) {
            next("/toBuyCard");
          } else {
            next();
          }
        }
      } else {
        next("/login");
      }
    });
  }
};
</script>
